/*
 * @Author: Drc
 * @Date: 2020-12-14 17:07:53
 * @LastEditTime: 2021-11-03 13:56:10
 * @LastEditors: Drc
 */
import http from '@path/utils/http'
import Token from '@path/config/token'
import {createModel} from '@rematch/core'
import {RootModel} from '@path/redux'
import Api from '@path/config/api'
import NavigationController from '@path/navigation/controller'

interface USERINFO {}

const defaultState = {
  userInfo: {} as USERINFO,
  token: '',
}

const user = createModel<RootModel>()({
  state: defaultState,
  reducers: {
    updateInfo(state: any, userInfo: USERINFO) {
      return {
        ...state,
        userInfo: {
          ...state.userInfo,
          ...userInfo,
        },
      }
    },
    updateToken(state: any, token: string) {
      return {
        ...state,
        token,
      }
    },
    resetInfo() {
      return defaultState
    },
  },
  effects: () => ({
    logout() {
      Token.remove()
      this.resetInfo()
      NavigationController.replace('LoginRoute')
    },
  }),
})

export default user
